package top.boycharse.ftp.server.common;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

public class ThreadPoolManager {

    public static int MAX_THREAD_NUM = 10;

    private static ThreadPoolManager manager;

    private ExecutorService service;

    private ThreadPoolManager() {
        service = Executors.newFixedThreadPool(MAX_THREAD_NUM);
    }

    public static ThreadPoolManager getInstance() {
        synchronized (ThreadPoolManager.class) {
            if (manager == null) {
                synchronized (ThreadPoolManager.class) {
                    if (manager == null) {
                        manager = new ThreadPoolManager();
                    }

                }
            }
        }
        return manager;
    }

    public void execute(Runnable runnable) {
        if (service != null) {
            service.execute(runnable);
        }
    }
}
